namespace Skymate.Commands
{
    using System;
    using System.Linq;

    using Abp.Events.Bus;

    using Skymate.Lyjt.Core;

    public class DatetimeResponseCommand : BaseLightCommand
    {
        public DatetimeResponseCommand()
            : base(ProtocolConst.OptionType.QueryResponse, ProtocolConst.ObjectType.Datetime)
        {
        }

        public override void ExecuteCommand(LightAppSession session, SemaphoreRequestInfo requestInfo)
        {
            var data = requestInfo.Body;

            var datetick = BitConverter.ToInt32(data.ToArray(), 0);
            var date = new DateTime(1970, 1, 1).AddSeconds(datetick);

            EventBus.Default.Trigger(new DatetimeResponseEvent(
                session.RemoteEndPoint.ToString(),
                date));
        }
    }
}